public class accumulator {

    public static void main(String[] args) {

        int[][] arr1 = new int[16][16];
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1[i].length; j++) {
                arr1[i][j] = j;
            }
        }

        //1、所有行中所有元素的累加和
        //i,j 是行列式的下标
        for (int i = 0; i < 16; i++) {
            int sumHang = 0;
            for (int j = 0; j < 16; j++) {
                sumHang += arr1[i][j];
            }
            System.out.println("第" + i + "行中所有元素的累加和是：" + sumHang);
        }

        System.out.println("---------------------------------");

        //2、所有列中所有元素的累加和
        for (int i = 0; i < 16; i++) {
            int sumLie = 0;
            for (int j = 0; j < 16; j++) {
                sumLie += arr1[j][i];
            }
            System.out.println("第" + i + "列中所有元素的累加和是：" + sumLie);
        }

        System.out.println("---------------------------------");

        //3、左上角到右下角的累加和
        int SumLeftUp2RightDown = 0;
        for (int i = 0; i < 16; i++) {
            for (int j = 0; j < 16; j++) {
                if (i == j) {
                    SumLeftUp2RightDown += arr1[i][j];
                }
            }
        }
        System.out.println("左上角到右下角的累加和是：" + SumLeftUp2RightDown);

        System.out.println("---------------------------------");

        //4、右上角到左下角的累加和
        int SumRightUp2LeftDown = 0;
        for (int i = 0; i < 16; i++) {
            for (int j = 0; j < 16; j++) {
                if (16 == i + j) {
                    SumRightUp2LeftDown += arr1[i][j];
                }
            }
        }
        System.out.println("左下角到右上角的累加和是：" + SumRightUp2LeftDown);
    }
}
